import workflow from '@/api/workflow'
import { getToken, setToken, removeToken } from '@/utils/auth'
import { resetRouter } from '@/router'
import { MessageBox, Message } from 'element-ui'


const getDefaultState = () => {
  return {

  }
}

const state = getDefaultState()

const mutations = {

}

const actions = {

  baseAction(func) {
    var promise = func();
    return new Promise((resolve, reject) => {

      promise.then(response => {
        if (response && response.code == 'success')
          resolve(response.data)
        else {
          debugger
          Message({
            message: response.msg,
            type: 'error',
            duration: 5 * 1000
          })
          reject(response.data)
        }
      }).catch(error => {
        reject(error)
      })
    })
  }
  ,
  // get user info
  getAllconditions({ commit, state }) {

    return actions.baseAction(() => {
      return workflow.getAllconditions();
    })
  },
  getAllUserSelectors({ commit, state }) {
    return actions.baseAction(() => {
      return workflow.getAllUserSelectors();
    })
  },
  getAllWorkflows({ commit, state }) {
    return actions.baseAction(() => {
      return workflow.getAllWorkflows();
    })
  },
  getUserSelectionsOfUserSelector({ commit, state }, params) {
    return actions.baseAction(() => {
      return workflow.getUserSelectionsOfUserSelector(params);
    })
  },
  createWorkFlow({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.createWorkFlow(data);
    })
  },
  getAllWorkflowVersions({ commit, state }, params) {
    return actions.baseAction(() => {
      return workflow.getAllWorkflowVersions(params);
    })
  },
  getWorkflowVersion({ commit, state }, params) {
    return actions.baseAction(() => {
      debugger
      return workflow.getWorkflowVersion(params);
    })
  },
  updateWorkflowActiveVersion({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.updateWorkflowActiveVersion(data);
    })
  },
  updateWorkflow({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.updateWorkflow(data);
    })
  },
  createWorkTask({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.createWorkTask(data);
    })
  },
  startWorkTask({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.startWorkTask(data);
    })
  },
  passProve({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.passProve(data);
    })
  },
  rejectProve({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.rejectProve(data);
    })
  },
  withdrawProve({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.withdrawProve(data);
    })
  }, forwardProve({ commit, state }, data) {
    return actions.baseAction(() => {
      return workflow.forwardProve(data);
    })
  },
  getAllTaskStepsOfWorkTask({ commit, state }, params) {
    return actions.baseAction(() => {
      return workflow.getAllTaskStepsOfWorkTask(params);
    })
  },
  clearSimulationRecord({ commit, state }) {
    return actions.baseAction(() => {
      return workflow.clearSimulationRecord();
    })
  },
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}

